home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / libhtml-tree-perl / examples / htmltree
Encoding:
Text File  |  2007-04-27  |  1.0 KB  |  51 lines

  1. #!/usr/bin/perl
  2. # Time-stamp: "2000-10-02 14:48:15 MDT"
  3. #
  4. # Parse the given HTML file(s) and dump the parse tree
  5. # Usage:
  6. #  htmltree -D3 -w file1 file2 file3
  7. #    -D[number]  sets HTML::TreeBuilder::Debug to that figure.
  8. #    -w  turns on $tree->warn(1) for the new tree
  9.  
  10. require 5;
  11. use strict;
  12.  
  13. my $warn;
  14.  
  15. BEGIN { # We have to set debug level before we use HTML::TreeBuilder.
  16.   $HTML::TreeBuilder::DEBUG = 0; # default debug level
  17.   $warn = 0;
  18.   while(@ARGV) {   # lameo switch parsing
  19.     if($ARGV[0] =~ m<^-D(\d+)$>s) {
  20.       $HTML::TreeBuilder::DEBUG = $1;
  21.       print "Debug level $HTML::TreeBuilder::DEBUG\n";
  22.       shift @ARGV;
  23.     } elsif ($ARGV[0] =~ m<^-w$>s) {
  24.       $warn = 1;
  25.       shift @ARGV;
  26.     } else {
  27.       last;
  28.     }
  29.   }
  30. }
  31.  
  32. use HTML::TreeBuilder;
  33.  
  34. foreach my $file (grep( -f $_, @ARGV)) {
  35.   print
  36.     "=" x 78, "\n",
  37.     "Parsing $file...\n";
  38.  
  39.   my $h = HTML::TreeBuilder->new;
  40.   $h->ignore_unknown(0);
  41.   $h->warn($warn);
  42.   $h->parse_file($file);
  43.  
  44.   print "- "x 39, "\n";
  45.   $h->dump();
  46.   $h = $h->delete(); # nuke it!
  47.   print "\n\n";
  48. }
  49. exit;
  50. __END__
  51.